package com.sys.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;

import com.sys.utils.RequestEncodingUtils;

/**
 * @ClassName: GlobalEncoding 
 * @Description: TODO(解决全局编码的filter) 
 * @author 詹金浩 
 * @date 2018年3月10日 下午10:26:09
 */
@WebFilter("/*")
public class GlobalEncoding implements Filter {

    /**
     * Default constructor. 
     */
    public GlobalEncoding() {
        // TODO Auto-generated constructor stub
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    	response.setContentType("text/html;charset=UTF-8");
    	RequestEncodingUtils myRequest = new RequestEncodingUtils((HttpServletRequest)request);
    	chain.doFilter(myRequest, response);
    }
    
	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

}
